import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router"
import Home from "../views/home/index.vue"
import Car from "../views/car/index.vue"
import Goods from "../views/goods/index.vue"
import Me from "../views/me/index.vue"
import Search from "../views/search/index.vue"
import Menu from "../views/menu/index.vue"
import Login from "../views/login/index.vue"
import Top from "../components/top.vue"
import TopHome from "../components/topHome.vue"
import City from "../views/city/index.vue"
import Register from "../views/register/index.vue"
const routes: RouteRecordRaw[] = [
    {
        path: "/",
        components: {
            default: Home,
            menu: Menu,
            Top: TopHome
        },
        meta: {
            til: "首页",
            hidden: false,
            icon: 'wap-home'
        },
        name: "home"
    },
    {
        path: "/car",
        components: {
            default: Car,
            menu: Menu,
            Top: Top,
        },
        meta: {
            til: "购物车",
            hidden: false,
            icon: 'shopping-cart'
        },
        name: "car"
    },
    {
        path: "/goods/:id",
        components: {
            default: Goods,
            Top: Top,
        },
        meta: {
            hidden: true,
            til: "详情",
            icon: 'orders-o'
        },
        name: "goods"
    },
    {
        path: "/search",
        components: {
            default: Search,
        },
        meta: {
            hidden: true,
            til: "搜索",
            icon: 'search'
        },
        name: "search"
    },
    {
        path: "/me",
        components: {
            default: Me,
            menu: Menu,
            Top: Top,
        },
        meta: {
            til: "我的",
            hidden: false,
            icon: 'gift'
        },
        name: "me",
    },
    {
        path: "/login",
        components: {
            default: Login,
            menu: Menu
        },
        meta: {
            til: "登录",
            hidden: false,
            icon: 'manager'
        },
        name: "login"
    },
    {
        path: "/city",
        components: {
            default: City,
        },
        meta: {
            til: "城市列表",
            hidden: true,
            icon: 'user-circle-o'
        },
        name: "city"
    },
    {
        path: "/register",
        redirect: "/register/step1",
        components: {
            default: Register,

        },
        meta: {
            til: "注册",
            hidden: true,
            icon: 'user-circle-o'
        },
        name: "注册",
        children: [
            {
                path: "step1",
                components: {
                    default: () => import("../views/register/step1.vue"),
                    Top: Top,
                },
                meta: {
                    til: "注册",
                    hidden: true,
                    icon: 'user-circle-o'
                },
                name: "注册",
            },
            {
                path: "step2",
                components: {
                    default: () => import("../views/register/step2.vue"),
                    Top: Top,
                },
                meta: {
                    til: "验证码",
                    hidden: true,
                    icon: 'user-circle-o'
                },
                name: "验证码",
            },
            {
                path: "step3",
                components: {
                    default: () => import("../views/register/step3.vue"),
                    Top: Top,
                },
                meta: {
                    til: "注册名称",
                    hidden: true,
                    icon: 'user-circle-o'
                },
                name: "注册名称",
            }
        ]
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})
router.beforeEach((to, from, next) => {
    //as string
    document.title = to.meta.til as string;
    next()
})
export default router;